package com.magicalcoder.youyaboot.admin.api.cancellationofinsurance;

import com.magicalcoder.youyaboot.core.common.constant.PageConstant;
import com.magicalcoder.youyaboot.core.serialize.ResponseMsg;
import com.magicalcoder.youyaboot.core.service.CommonRestController;
import com.magicalcoder.youyaboot.model.Cancellationofinsurance;
import com.magicalcoder.youyaboot.service.cancellationofinsurance.service.CancellationofinsuranceService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;


/**
* 代码为自动生成 Created by www.magicalcoder.com
* 软件作者：何栋宇 qq:709876443
* 如果你改变了此类 read 请将此行删除
* 欢迎加入官方QQ群:648595928
*/

@RequestMapping("/admin/cancellationofinsurance_rest/")
@RestController
public class AdminCancellationofinsuranceRestController extends CommonRestController<Cancellationofinsurance,Integer> implements InitializingBean
{

    @Resource
    private CancellationofinsuranceService cancellationofinsuranceService;

        //分页查询
    @RequestMapping(value={"page"}, method={RequestMethod.GET})
    public ResponseMsg page(
        @RequestParam(required = false,value ="guaranteeIdFirst")                            String guaranteeIdFirst ,
        @RequestParam int page,@RequestParam int limit,@RequestParam(required = false) String safeOrderBy
        ,HttpServletResponse response,@RequestParam(required = false) Integer queryType
    ){
        Map<String,Object> query = new HashMap();
        query.put("guaranteeIdFirst",coverBlankToNull(guaranteeIdFirst));
        Integer count = cancellationofinsuranceService.getModelListCount(query);
        query.put("safeOrderBy",safeOrderBy);
        if(queryType==null || queryType == QUERY_TYPE_SEARCH){//普通查询
            limit = Math.min(limit, PageConstant.MAX_LIMIT);
            query.put("start",(page - 1) * limit);query.put("limit",limit);
            return new ResponseMsg(count,cancellationofinsuranceService.getModelList(query));
        }else if(queryType == QUERY_TYPE_EXPORT_EXCEL){
            query.put("start",(page - 1) * limit);query.put("limit",limit);
            exportExcel(response,cancellationofinsuranceService.getModelList(query),"注销投保明细表",
            new String[]{"主键","保单编号","保险编号","优惠","基本保费","费率","内部优惠","内部优惠率","无事故优惠","无事故优惠率","浮动金额","浮动比例","应交费用","备注"},
            new String[]{"","","","","","","","","","","","","",""});
        }
        return null;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        super.commonService = cancellationofinsuranceService;
        super.primaryKey = "id";//硬编码此实体的主键名称
    }
}
